using System;
using System.Data;
using FirebirdSql.Data.FirebirdClient;

namespace Jandaya.Framework.DAO
{
	public abstract class DAO<T> : IDAO<T>
	{
		
		/// <summary>
		/// Business object
		/// </summary>
		public T BO { get; set; }
		
		protected FbConnection Connection{ get; set; }
		
		public DAO(){}

		public DAO(T pBussinessObject, FbConnection pConnection)
		{
			BO = pBussinessObject;
			Connection = pConnection;
		}		
		
		#region 'IDAOObject'
        public virtual bool Load(Int64 ID){
			throw new NotImplementedException();
		}
		
        public virtual bool Save(){
			throw new NotImplementedException();
		}
		
        public virtual bool Insert(){
			throw new NotImplementedException();
		}
		
        public virtual bool Update(){
			throw new NotImplementedException();
		}
		
        public virtual bool Delete(){
			throw new NotImplementedException();
		}			
		#endregion
		
		
		#region 'bind functions'
		public virtual bool Bind(DataRow pRow){
			throw new NotImplementedException();
		}			
		
		public virtual bool Bind(FbDataReader pReader){
			throw new NotImplementedException();
		}			
		#endregion
		
		
		#region 'Utility functions'
		public FbCommand GetCommand(string pSql){
			FbCommand result = new FbCommand(pSql, Connection);
			return result;
		}
		
		public FbCommand GetCommand(string pSql, CommandType pCommandType){
			FbCommand result = GetCommand(pSql);
			result.CommandType = pCommandType;
			return result;
		}
		
		public FbDataReader GetDataReader(string pSql){
			return GetCommand(pSql).ExecuteReader();
		}
		
		public FbDataAdapter GetAdapter(string pSql){
			FbDataAdapter result = new FbDataAdapter(pSql, Connection);
			return result;
		}
		
		public DataTable GetDataTable(string pSql){
			DataTable result = new DataTable();
			GetAdapter(pSql).Fill(result);
			return result;
		}
		#endregion
	}
}

